<!DOCTYPE html>
<html>

<head>
  <meta charset="UTF-8">
  <title>singwa赛事直播-主持人页面</title>
  <meta name="renderer" content="webkit">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <!--   <meta name="viewport" content="width=device-width,user-scalable=yes, minimum-scale=0.4, initial-scale=0.8,target-densitydpi=low-dpi" /> -->
  <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon" />


  <link rel="stylesheet" href="./css/font.css">
  <link rel="stylesheet" href="./css/xadmin.css">
  <script type="text/javascript" src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
  <script type="text/javascript" src="./lib/layui/layui.js" charset="utf-8"></script>
  <script type="text/javascript" src="./js/xadmin.js"></script>

  <link rel="stylesheet" type="text/css" href="../uploader/webuploader.css">
  <script type="text/javascript" src="../uploader/webuploader.js"></script>
  <!-- 让IE8/9支持媒体查询，从而兼容栅格 -->
    <!--[if lt IE 9]>
      <script src="https://cdn.staticfile.org/html5shiv/r29/html5.min.js"></script>
      <script src="https://cdn.staticfile.org/respond.js/1.4.2/respond.min.js"></script>
    <![endif]-->

  </head>

  <body>
    <div class="x-body">
      <form class="layui-form">

        <div class="layui-form-item">
          <label for="username" class="layui-form-label">
            <span class="x-red">*</span>第几节
          </label>
          <div class="layui-input-inline">
            <select id="type" name="type" class="valid">
              <option value="1">第一节</option>
              <option value="2">第二节</option>
              <option value="3">第三节</option>
              <option value="4">第四节</option>
            </select>
          </div>
        </div>
        <div class="layui-form-item">
          <label for="username" class="layui-form-label">
            <span class="x-red">*</span>球队
          </label>
          <div class="layui-input-inline">
            <select id="team_id" name="team_id" class="valid">
              <option value="0">请选择</option>
              <option value="1">马刺</option>
              <option value="4">火箭</option>
            </select>
          </div>
        </div>


        <div class="layui-form-item layui-form-text">
          <label for="desc" class="layui-form-label">
            赛况内容
          </label>
          <div class="layui-input-block">
            <textarea placeholder="请输入内容" id="content" name="content" class="layui-textarea"></textarea>
          </div>
        </div>
        <div class="layui-form-item layui-form-text">
          <label for="desc" class="layui-form-label">
            客户端
          </label>
          <div class="layui-input-block">
            <input type="text" name="fd" value="">
          </div>
        </div>

        <div class="layui-form-item layui-form-text">
          <label for="desc" class="layui-form-label">
            赛况图
          </label>
          <!--dom结构部分-->
          <div id="uploader-demo">
            <!--用来存放item-->
            <div id="fileList" class="uploader-list"></div>
            <div id="filePicker">选择图片</div>
          </div>


        </div>


        <script>

         var $ = jQuery,
         $list = $('#fileList'),
         ratio = window.devicePixelRatio || 1,
         thumbnailWidth = 100 * ratio,
         thumbnailHeight = 100 * ratio,
         uploader;
         uploader = WebUploader.create({
          auto: true,
          swf: 'http://www.test.com:8811/uploader/Uploader.swf',
          server: 'http://www.test.com:8811/?s=admin/image/index',
          pick: '#filePicker',
          accept: {
            title: 'Images',
            extensions: 'gif,jpg,jpeg,bmp,png',
            mimeTypes: 'image/*'
          }
        });
         uploader.on( 'fileQueued', function( file ) {
          var $li = $(
            '<div id="' + file.id + '" class="file-item thumbnail">' +
            '<img>' +
            '<div class="info">' + file.name + '</div>' +
            '</div>'
            ),
          $img = $li.find('img');
          $list.append( $li );
          uploader.makeThumb( file, function( error, src ) {
            if ( error ) {
              $img.replaceWith('<span>不能预览</span>');
              return;
            }
            $img.attr( 'src', src );
          }, thumbnailWidth, thumbnailHeight );
        });

          // 文件上传过程中创建进度条实时显示。
          uploader.on( 'uploadProgress', function( file, percentage ) {
            var $li = $( '#'+file.id ),
            $percent = $li.find('.progress span');

            if ( !$percent.length ) {
              $percent = $('<p class="progress"><span></span></p>')
              .appendTo( $li )
              .find('span');
            }

            $percent.css( 'width', percentage * 100 + '%' );
          });

          uploader.on( 'uploadSuccess', function( file, data ) {
            if(data.status){
              $('#'+file.id).append('<input type="hidden" name="image" value="'+data.data.image+'"/>');
            }
            $( '#'+file.id ).addClass('upload-state-done');
          });

          uploader.on( 'uploadError', function( file ) {
            var $li = $( '#'+file.id ),
            $error = $li.find('div.error');

            if ( !$error.length ) {
              $error = $('<div class="error"></div>').appendTo( $li );
            }

            $error.text('上传失败');
          });

          uploader.on( 'uploadComplete', function( file ) {
            $( '#'+file.id ).find('.progress').remove();
          });
        </script>

        <div class="layui-form-item">
          <label for="L_repass" class="layui-form-label">
          </label>
          <button  type="submit" class="layui-btn"  lay-filter="add" id="submit-btn" lay-submit="">
            增加
          </button>
        </div>
      </form>
    </div>
    <script>


      var $submitBtn = $('#submit-btn');
        // 提交表单
        $submitBtn.click(function (event) {
          event.preventDefault();
          var formData = $('form').serialize();
          // TODO: 请求后台接口跳转界面，前端跳转或者后台跳
          $.get("http://www.test.com:8811/?s=admin/live/push&" + formData, function (data) {

            if (data.status == 1) {
              // 登录成功
            }
            // location.href='index.html';
          }, 'json');
        });



      </script>
      <script>var _hmt = _hmt || []; (function() {
        var hm = document.createElement("script");
        hm.src = "https://hm.baidu.com/hm.js?b393d153aeb26b46e9431fabaf0f6190";
        var s = document.getElementsByTagName("script")[0];
        s.parentNode.insertBefore(hm, s);
      })();</script>
    </body>

    </html>